﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Ayatta.Contract.Domain
{
    /// <summary>
    /// 游戏
    /// </summary>
    public class Game : BaseEntity<int>
    {
        /// <summary>
        /// 类型
        /// </summary>
        public GameType Type { get; set; }

        /// <summary>
        /// 分类
        /// </summary>
        public GameCategory Category { get; set; }

        /// <summary>
        /// 首字母
        /// </summary>
        public char Initial { get; set; }

        /// <summary>
        /// 游戏名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 游戏子名称
        /// </summary>
        public string SubName { get; set; }

        /// <summary>
        /// 官网名
        /// </summary>
        public string SiteName { get; set; }

        /// <summary>
        /// 图标URL
        /// </summary>
        public string Icon { get; set; }

        /// <summary>
        /// 图片URL
        /// </summary>
        public string Picture { get; set; }

        /// <summary>
        /// 背景图URL
        /// </summary>
        public string BgImg { get; set; }

        /// <summary>
        /// 是否为热门游戏
        /// </summary>
        public bool IsHot { get; set; }

        /// <summary>
        /// 是否为精品游戏
        /// </summary>
        public bool IsRefined { get; set; }

        /// <summary>
        /// 显示位置
        /// </summary>
        public int ShowOn { get; set; }

        /// <summary>
        /// 摘要
        /// </summary>
        public string Summary { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 第三方游戏参数
        /// </summary>
        public string Params { get; set; }

        /// <summary>
        /// 开放时间
        /// </summary>
        public DateTime OpendOn { get; set; }

        /// <summary>
        /// 优先级 数值从大到小
        /// </summary>
        public int Priority { get; set; }

        /// <summary>
        /// 扩展信息
        /// </summary>
        public string Extra { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public bool Status { get; set; }


        /// <summary>
        /// 服
        /// </summary>
        public virtual IEnumerable<GameServer> Servers { get; set; }

        public static IDictionary<GameCategory, string> Categories
        {
            get
            {
                var dic = new Dictionary<GameCategory, string>();
                dic.Add(GameCategory.Rpg, "角色扮演");
                return dic;
            }
        }

        public GameServer GetLatest()
        {
            return Servers.FirstOrDefault(o => o.GameId == Id && o.Status && DateTime.Now >= o.OpendOn);
        }
    }

    /// <summary>
    /// 游戏类型
    /// </summary>
    public enum GameType : byte
    {
        WebGame = 0
    }

    /// <summary>
    /// 游戏分类
    /// </summary>
    public enum GameCategory : byte
    {
        /// <summary>
        /// 角色扮演
        /// </summary>
        Rpg = 0
    }
}